package com.zr.sms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.sms.service.Goodsinfomanageservice;
import com.zr.sms.serviceimpl.Goodsinfomanageserviceimpl;

import net.sf.json.JSONObject;
/**
 * 查询商品控制层的实现
 * @author 吴浩
 *
 */
public class FindgoodsServlet extends HttpServlet{
	Goodsinfomanageservice gifs=new Goodsinfomanageserviceimpl();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
	req.setCharacterEncoding("utf-8");
	resp.setCharacterEncoding("utf-8");

	PrintWriter pw=resp.getWriter();
	HttpSession session=req.getSession();
	int page = Integer.parseInt(req.getParameter("page"));
	int pagesize = Integer.parseInt(req.getParameter("rows"));
	int start =  (page-1)*pagesize;
	JSONObject 	goods=gifs.getGoods(start, pagesize);
	
	String searchname=req.getParameter("searchname");
	if (searchname!=null) {
		goods=gifs.getGoods(start, pagesize,searchname);
	}
	else {
		goods=gifs.getGoods(start, pagesize);
	}
	    pw.write(goods.toString());
	}
}
